package com.kaifamiao.www.IP.do0928;

import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;


public class GroupReceiveDemo {
    public static void main(String[] args) throws Exception{
        //创建接收端Socket对象(MulticastSocket)
        MulticastSocket socket = new MulticastSocket(8888);
        //创建一个箱子，用于接收对象
        DatagramPacket packet = new DatagramPacket(new byte[1024],1024);
        //绑定组播地址
        socket.joinGroup(InetAddress.getByName("224.0.1.0"));
        //将数据接收到箱子中
        socket.receive(packet);
        //解析数据
        byte[] data = packet.getData();
        int len = packet.getLength();
        System.out.println(new String(data,0,len));
        socket.close();

    }
}
